﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Writer.API.Appliaction.Commends.Zmc.Warehou;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.Appliaction.CommandHandlers.Zmc.Warehou
{
    public class WarehousStutasWarehousIdCommendHandlers : IRequestHandler<WarehousStutasWarehousIdCommends, ApiResult<int>>
    {
        private readonly ISqlSugarClient db;

        public WarehousStutasWarehousIdCommendHandlers(ISqlSugarClient db)
        {
            this.db = db;
        }

        /// <summary>
        /// 依据主键修改入库状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(WarehousStutasWarehousIdCommends request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = ApiEnums.修改成功;
            result.Msg = "修改成功";
            var res = db.Queryable<Warehous>().FirstAsync(p=>p.WarehousId==request.WarehousId).Result;
            res.Status = 1;
         
            
          
            var newres = db.Updateable(res).ExecuteCommand();
            if (newres != null)
            {
                result.Code = ApiEnums.修改成功;
                result.Msg = "修改成功";
                result.Data = newres;

            }
            else
            {
                result.Code = ApiEnums.修改失败;
                result.Msg = "修改失败";
            }

            return result;
        }
    }
}
